home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.05 May 91 / Math Parser ƒ / Node Stuff / GetNodeTable < prev    next >
Encoding:
Text File  |  1990-08-21  |  4.0 KB  |  154 lines  |  [TEXT/PJMM]

  1. unit GetNodeTable;
  2.  
  3.  
  4. interface
  5.  
  6.     uses
  7.         ParserGlobals, StringStuff, GetTokenTypes, Parser, GetFunctionPlaces;
  8.  
  9.     procedure getnodetable (var nodetable: hdlnoderecord; var nodepointer: integer; var error: str255; var store: boolean; var save: array2);
  10.  
  11.  
  12. implementation
  13.  
  14.  
  15.     procedure getnodetable;
  16.  
  17.         label
  18.             991, 999;
  19.  
  20.         type
  21.  
  22.             placetype = record
  23.                     typetoken: stringsize;
  24.                     pos: integer;
  25.                     strt: integer;
  26.                     stp: integer;
  27.                 end;
  28.             ptrplacetype = ^placetype;
  29.             hdlplacetype = ^ptrplacetype;
  30.  
  31.         var
  32.             i, j, k, l, m, jtot, ktot, numnodeplaces: integer;
  33.             numplaces: hdlintarray0;
  34.             sysub: hdlstringarray0;
  35.             subtokentype: hdlstringarray0;
  36.             nst, nend: hdlintarray0;
  37.             nodeplace: array[1..maxnumberofnodes] of hdlplacetype;
  38.             subpr: hdlintarray0;
  39.  
  40.     begin
  41.  
  42.         nodepointer := 0;
  43.  
  44.         numplaces := hdlintarray0(NewHandle(SizeOf(intarray0)));
  45.         nst := hdlintarray0(NewHandle(SizeOf(intarray0)));
  46.         nend := hdlintarray0(NewHandle(SizeOf(intarray0)));
  47.  
  48.         sysub := hdlstringarray0(NewHandle(SizeOf(stringarray0)));
  49.         subtokentype := hdlstringarray0(NewHandle(SizeOf(stringarray0)));
  50.         subpr := hdlintarray0(NewHandle(SizeOf(intarray0)));
  51.  
  52.         getfunctionplaces(numnodeplaces, numplaces, nst, nend);
  53.  
  54.         for j := 1 to numnodeplaces do
  55.             begin
  56.                 nodeplace[j] := hdlplacetype(NewHandle(SizeOf(placetype)));
  57.                 nodeplace[j]^^.typetoken := tokentype^^[numplaces^^[j]];
  58.                 nodeplace[j]^^.pos := numplaces^^[j];
  59.                 nodeplace[j]^^.strt := nst^^[j];
  60.                 nodeplace[j]^^.stp := nend^^[j];
  61.             end;
  62.  
  63.         for m := 1 to numnodeplaces do
  64.             begin
  65.                 i := numnodeplaces + 1 - m;
  66.                 ktot := nodeplace[i]^^.stp + 1 - nodeplace[i]^^.strt;
  67.                 for j := nodeplace[i]^^.strt to nodeplace[i]^^.stp do
  68.                     begin
  69.                         k := j + 1 - nodeplace[i]^^.strt;
  70.                         l := k + nodeplace[i]^^.pos;
  71.  
  72.                         sysub^^[k] := sy^^[l];
  73.                         subtokentype^^[k] := tokentype^^[l];
  74.                         subpr^^[k] := pr^^[l];
  75.                     end;
  76.  
  77.                 sysub^^[0] := sy^^[0];
  78.                 subtokentype^^[0] := tokentype^^[0];
  79.                 subpr^^[0] := pr^^[0];
  80.  
  81.                 ktot := ktot + 1;
  82.                 sysub^^[ktot] := sy^^[ntot];
  83.                 subtokentype^^[ktot] := tokentype^^[ntot];
  84.                 subpr^^[ktot] := pr^^[ntot];
  85.  
  86.  
  87.                 if ktot = 2 then
  88.                     begin
  89.                         nodepointer := nodepointer + 1;
  90.                         nodetable^^[nodepointer].optype := 'unary';
  91.                         nodetable^^[nodepointer].loptype := tokentype^^[nodeplace[i]^^.strt];
  92.                         nodetable^^[nodepointer].roptype := tokentype^^[nodeplace[i]^^.strt];
  93.                         nodetable^^[nodepointer].op.index := plus;
  94.                         nodetable^^[nodepointer].lop.index := sy^^[nodeplace[i]^^.strt];
  95.                         nodetable^^[nodepointer].rop.index := sy^^[nodeplace[i]^^.strt];
  96.                         goto 991;
  97.                     end;
  98.  
  99.                 parser(sysub, subtokentype, subpr, nodetable, nodepointer, error);
  100.  
  101.                 if error <> '' then
  102.                     goto 999;
  103.  
  104. 991:
  105.                 nodepointer := nodepointer + 1;
  106.                 nodetable^^[nodepointer].optype := nodeplace[i]^^.typetoken;
  107.                 nodetable^^[nodepointer].loptype := 'node';
  108.                 nodetable^^[nodepointer].roptype := 'node';
  109.                 nodetable^^[nodepointer].op.index := sy^^[nodeplace[i]^^.pos];
  110.                 nodetable^^[nodepointer].lop.index := stringof(nodepointer - 1);
  111.                 nodetable^^[nodepointer].rop.index := stringof(nodepointer - 1);
  112.  
  113.                 sy^^[nodeplace[i]^^.pos] := stringof(nodepointer);
  114.                 tokentype^^[nodeplace[i]^^.pos] := 'node';
  115.                 pr^^[nodeplace[i]^^.pos] := 0;
  116.  
  117.                 for j := nodeplace[i]^^.stp + 1 to ntot do
  118.                     begin
  119.                         k := j - nodeplace[i]^^.stp;
  120.                         sy^^[k + nodeplace[i]^^.pos] := sy^^[j];
  121.                         tokentype^^[k + nodeplace[i]^^.pos] := tokentype^^[j];
  122.                         pr^^[k + nodeplace[i]^^.pos] := pr^^[j];
  123.                     end;
  124.  
  125.                 ntot := ntot - (ktot - 1);
  126.  
  127.                 for l := 1 to i - 1 do
  128.                     if nodeplace[l]^^.stp > nodeplace[i]^^.stp then
  129.                         nodeplace[l]^^.stp := nodeplace[l]^^.stp - (ktot - 1);
  130.  
  131.             end;
  132.  
  133.         parser(sy, tokentype, pr, nodetable, nodepointer, error);
  134.  
  135.         ntot := jtot;
  136.  
  137.         if (save[2] = equals) then
  138.             store := true;
  139.  
  140. 999:
  141.  
  142.         for k := 1 to numnodeplaces do
  143.             DisposHandle(handle(nodeplace[k]));
  144.  
  145.         DisposHandle(handle(numplaces));
  146.         DisposHandle(handle(nst));
  147.         DisposHandle(handle(nend));
  148.         DisposHandle(handle(sysub));
  149.         DisposHandle(handle(subtokentype));
  150.         DisposHandle(handle(subpr));
  151.  
  152.     end;
  153.  
  154. end.